package com.woniu.controller.backpage;

import com.woniu.entity.*;
import com.woniu.service.backpage.IDepotService;
import com.woniu.service.backpage.IGoodsService;
import com.woniu.service.backpage.IGoodsTypesService;
import com.woniu.service.homePage.ISortingAppService;
import com.woniu.util.RequestParams;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class GoodsController {

    @Autowired(required = false)
    private IGoodsService goodsService;

    @Autowired(required = false)
    private IDepotService depotService;

    @Autowired(required = false)
    private IGoodsTypesService goodsTypeService;

    @Autowired
    private ISortingAppService sortingAppService;

    @RequestMapping("findGoodsByConditions")
    public ResData<?> findGoodsByConditions(@RequestBody RequestParams<Goods> requestParams){
        return goodsService.findGoodsByConditions(requestParams);
    }

    @RequestMapping("findGoodsTypeByConditions")
    public ResData<?> findGoodsTypeByConditions(@RequestBody RequestParams<GoodsType> requestParams){
        return goodsTypeService.findGoodsTypeByConditions(requestParams);
    }

    @RequestMapping("deleteGoods")
    public ResData<?> deleteGoods(@RequestBody RequestParams<Goods> requestParams){
        if(requestParams.getData().getPutOn()==1){
            requestParams.getData().setPutOn(0);
        }else{
            requestParams.getData().setPutOn(1);
        }
        return goodsService.deleteGoods(requestParams);

    }

    @RequestMapping("updateGoods")
    public ResData<?> updateGoods(@RequestBody Goods goods){

        return goodsService.updateGoods(goods);

    }

    @RequestMapping("insertGoods")
    public ResData<?> insertGoods(@RequestBody Goods goods){

        return goodsService.insertGoods(goods);

    }

    @RequestMapping("updateRushPurchaseStatus")
    public ResData<?> updateRushPurchaseStatus(@RequestBody RushPurchase rushPurchase){
        System.out.println(rushPurchase);
        return goodsService.updateRushPurchaseStatus(rushPurchase);
    }

    @RequestMapping("deleteGoodsType")
    public ResData<?> deleteGoodsType(Integer id){
        return goodsTypeService.deleteGoodsType(id);

    }

    @RequestMapping("findFirstGoodsType")
    public ResData<?> findFirstGoodsType(){
        return goodsTypeService.findFirstGoodsType();
    }

    @RequestMapping("addFirstLevel")
    public ResData<?> insertFirstLevel(@RequestBody GoodsType goodsType){
        return goodsTypeService.insertFirstLevel(goodsType);
    }

    @RequestMapping("addSecondLevel")
    public ResData<?> insertSecondLevel(@RequestBody GoodsType goodsType){
        return goodsTypeService.insertSecondLevel(goodsType);
    }

    @RequestMapping("getRootGoodsType")
    public ResData<?> getRootGoodsType(){
        return goodsTypeService.getStructuredGoodsType();
    }

    @RequestMapping("findGoodsByName")
    public ResData<?> findGoodsByName(String name){
        return goodsService.findGoodsByName(name);
    }

    @RequestMapping("insertRushPurchase")
    public ResData<?> insertRushPurchase(@RequestBody RushPurchase rushPurchase){
        return goodsService.insertRushPurchase(rushPurchase);
    }

    //查询所有仓库名称
    @RequestMapping("getAllDepotName")
    public ResData<?> getAllDepotName(){
        return depotService.getAllDepotName();
    }

    @RequestMapping("/insertImage")
    public ResData<?> insertImage(@RequestBody Image image){
        return sortingAppService.insertImage(image);
    }

    @RequestMapping("/insertGoodsImage")
    public ResData<?> insertGoodsImage(@RequestBody GoodsImage goodsImage){
        return sortingAppService.insertGoodsImage(goodsImage);
    }

    @RequestMapping("/findImgByImgUrl")
    public ResData<?> findImgByImgUrl(@RequestBody Image image){
        return sortingAppService.findImageByImgUrl(image);
    }

    @RequestMapping("batchInsertGoodsTag")
    public ResData<?> batchInsertGoodsImage(@RequestBody Tag tag){
        return goodsService.batchInsertGoodsImage(tag.getGoodsId(), tag.getTagIds());
    }

}
